package cst.neu.yuejian_31.model;

import java.util.List;

import cst.neu.yuejian_31.bean.CollectClubBean;
import cst.neu.yuejian_31.iface.CollectClubIface;
import cst.neu.yuejian_31.iface.CollectClubListener;
import cst.neu.yuejian_31.service.CollectClubService;
import cst.neu.yuejian_31.Common.Constant;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by xxe on 2017/10/26.
 */

public class CollectClubModel implements CollectClubIface {
    private Retrofit retrofit;
    public CollectClubModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getCollectClub(String userId, final CollectClubListener collectClubListener) {
        CollectClubService collectClubService=retrofit.create(CollectClubService.class);
        Call<List<CollectClubBean>>call=
                collectClubService.getClubCollect(userId);
        call.enqueue(new Callback<List<CollectClubBean>>() {
            @Override
            public void onResponse(Call<List<CollectClubBean>> call, Response<List<CollectClubBean>> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    collectClubListener.onSuccess(response.body());
                }else {
                    collectClubListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<List<CollectClubBean>> call, Throwable t) {
                collectClubListener.onFail(t.toString());
            }
        });
    }
}
